﻿Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization.Formatters.Soap
Public Class frmProjectResult
    Private Sub frmProjectResult_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        m_CreateTree()
        '设置工具档上的下拉框


    End Sub
    Private Sub m_CreateTree()
        Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(AermodProject0.SaveName).DirectoryName
        Dim strNameLast As String = CAermod.GetFileName(AermodProject0.SaveName)



        TreeView1.Nodes.Clear() '删除现有项目
        Dim newNode1 As TreeNode = New TreeNode(CAermod.GetFileName(AermodProject0.SaveName)) '第1层节点
        Dim newNode2 As TreeNode '第二层节点
        Dim newNode3 As TreeNode '第三层节点
        '添加新的工程
        TreeView1.Nodes.Add(newNode1)
        For i As Integer = 0 To AermodProject0.ProjSetCollection.Count - 1

            newNode2 = newNode1.Nodes.Add(AermodProject0.ProjSetCollection.Item(i).ProjName & AermodProject0.ProjSetCollection.Item(i).PolluteName) '方案名
            newNode2.Text = AermodProject0.ProjSetCollection.Item(i).ProjName
            Dim strTempName As String = PrjPath & "\" & strNameLast & "\" & "Aermod\" & AermodProject0.ProjSetCollection.Item(i).ID & "\" & "TempAermod.aer" '获得保存结果方案文件的文件名
            If My.Computer.FileSystem.FileExists(strTempName) = False Then
                Exit Sub
            End If
            '打开方案的结果文件------------------------------
            Dim fileStr As Stream
            Dim formatter As IFormatter
            Try
                fileStr = File.Open(strTempName, FileMode.Open)

                formatter = CType(New BinaryFormatter, IFormatter)
                fileStr.Seek(0, SeekOrigin.Begin)
                Dim obj As Object = formatter.Deserialize(fileStr)
                fileStr.Dispose()
                ' All done
                fileStr.Close()
                AermodProject0.ProjSetCollection.Item(i).TempAermod = obj
            Catch ex As Exception
                fileStr.Dispose()
                fileStr.Close()
                MsgBox("在反序列化方案结果文件时出现意外错误!")
                Exit Sub
            End Try
            If AermodProject0.ProjSetCollection.Item(i).TempAermod.IsRuned = True Then
                newNode2.Text = newNode2.Text & "(已计算)"
                newNode3 = New TreeNode("各点高值")
                newNode3.Text = "各点高值"
                newNode2.Nodes.Add(newNode3)

                newNode3 = New TreeNode("所有点最大值")
                newNode3.Text = "所有点最大值"
                newNode2.Nodes.Add(newNode3)
                If AermodProject0.ProjSetCollection.Item(i).TempAermod.OutPutOption.PostCareFile.IsPost = True Then
                    newNode3 = New TreeNode("逐步值")
                    newNode3.Text = "逐步值"
                    newNode2.Nodes.Add(newNode3)

                    newNode3 = New TreeNode("超标率分析")
                    newNode3.Text = "超标率分析"
                    newNode2.Nodes.Add(newNode3)
                End If
            Else
                newNode2.Text = newNode2.Text & "(未计算)"
            End If
        Next

        '展开所有节点
        TreeView1.ExpandAll()
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

    End Sub
    Private Sub SetResultControl(ByVal strText As String)
        My.Application.ApplicationContext.MainForm.Cursor = Cursors.WaitCursor

        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Dim myTreeNode As TreeNode
        '如果结点没有窗口则新建，否则激活
        If Me.TreeView1.SelectedNode IsNot Nothing Then
            myTreeNode = Me.TreeView1.SelectedNode






            If myTreeNode.Text = "各点高值" Then

                '设置控制窗口的类型为各点高值
                myFrmMain.frmAnalyse.frmResultControl.FileType = FileType.Rectable
                '设置控制窗口的下拉框

                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AllPolluts.AllSelectPollut(0).Dispersion.DEPOS = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = True
                Else
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = False
                End If

                myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup(i).Name)
                Next


                myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime(i).ToString)
                Next
                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.Period = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add("期间平均")
                End If

                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.OutPutOption.Rectable.MaxCon
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Add("第" & i + 1 & "大")
                Next

                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart(i).Netid)
                Next


                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Enabled = True
                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Enabled = True

                myFrmMain.frmAnalyse.frmResultControl.cmbOver.SelectedIndex = 0
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.lstTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.txtSearchTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.cmdSearth.Visible = False

                myFrmMain.frmAnalyse.frmGridResult.Show()
                myFrmMain.frmAnalyse.frmGridResult.TabText = "网格点高值"
                myFrmMain.frmAnalyse.frmGridResult.Text = "网格点高值"
                myFrmMain.frmAnalyse.frmGis_Map.Show()
                'myFrmMain.frmAnalyse.m_vtkRenderForm.Show()
                myFrmMain.frmAnalyse.frmRectable.Activate()
                myFrmMain.frmAnalyse.frmRectable.TabText = "关心点高值"
                myFrmMain.frmAnalyse.frmRectable.Text = "关心点高值"

            ElseIf myTreeNode.Text = "所有点最大值" Then
                '设置控制窗口的类型为所有点高值
                myFrmMain.frmAnalyse.frmResultControl.FileType = FileType.Maxtable
                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AllPolluts.AllSelectPollut(0).Dispersion.DEPOS = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = True
                Else
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = False
                End If



                '设置工具档上的下拉框
                myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup(i).Name)
                Next


                myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime(i).ToString)
                Next

                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.Period = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add("期间平均")
                End If
                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.SelectedIndex = 0
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.lstTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.txtSearchTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.cmdSearth.Visible = False

                myFrmMain.frmAnalyse.frmGridResult.Hide()
                myFrmMain.frmAnalyse.frmGis_Map.Hide()
                'myFrmMain.frmAnalyse.m_vtkRenderForm.Hide()
                myFrmMain.frmAnalyse.frmRectable.TabText = "所有点最大值"
                myFrmMain.frmAnalyse.frmRectable.Text = "所有点最大值"
            ElseIf myTreeNode.Text = "逐步值" Then
                '设置控制窗口的类型为逐步值
                myFrmMain.frmAnalyse.frmResultControl.FileType = FileType.Post
                '设置gis绘图工具档上的下拉框
                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AllPolluts.AllSelectPollut(0).Dispersion.DEPOS = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = True
                Else
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = False
                End If

                myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup(i).Name)
                Next


                myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime(i).ToString)
                Next



                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.OutPutOption.Rectable.MaxCon
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Add("第" & i + 1 & "大")
                Next

                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart(i).Netid)
                Next
                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Enabled = True
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.SelectedIndex = 0
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.lstTime.Visible = True
                myFrmMain.frmAnalyse.frmResultControl.txtSearchTime.Visible = True
                myFrmMain.frmAnalyse.frmResultControl.cmdSearth.Visible = True

                myFrmMain.frmAnalyse.frmGridResult.Show()
                myFrmMain.frmAnalyse.frmGridResult.TabText = "网格点逐步值"
                myFrmMain.frmAnalyse.frmGridResult.Text = "网格点逐步值"
                myFrmMain.frmAnalyse.frmGis_Map.Show()
                'myFrmMain.frmAnalyse.m_vtkRenderForm.Show()
                myFrmMain.frmAnalyse.frmRectable.Activate()
                myFrmMain.frmAnalyse.frmRectable.TabText = "关心点逐步值"
                myFrmMain.frmAnalyse.frmRectable.Text = "关心点逐步值"
            ElseIf myTreeNode.Text = "超标率分析" Then

                myFrmMain.frmAnalyse.frmResultControl.FileType = FileType.Over
                '设置gis绘图工具档上的下拉框
                If myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AllPolluts.AllSelectPollut(0).Dispersion.DEPOS = True Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = True
                Else
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.Enabled = False
                End If


                myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Source.Groups.ArrayGroup(i).Name)
                Next

                myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Control.AerageingTime.GetSelectedAerageingTime(i).ToString)
                Next



                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.OutPutOption.Rectable.MaxCon
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Add("第" & i + 1 & "大")
                Next



                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Clear()
                For i As Integer = 0 To myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart.Length - 1
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Add(myFrmMain.frmAnalyse.NowProj.TempAermod.Receptor.SubGridCart(i).Netid)
                Next
                myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Enabled = False
                myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Enabled = True
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.SelectedIndex = 0
                myFrmMain.frmAnalyse.frmResultControl.cmbOver.Enabled = True
                myFrmMain.frmAnalyse.frmResultControl.lstTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.txtSearchTime.Visible = False
                myFrmMain.frmAnalyse.frmResultControl.cmdSearth.Visible = False

                myFrmMain.frmAnalyse.frmGridResult.Show()
                myFrmMain.frmAnalyse.frmGridResult.TabText = "网格点超标率"
                myFrmMain.frmAnalyse.frmGridResult.Text = "网格点超标率"
                myFrmMain.frmAnalyse.frmGis_Map.Show()
                'myFrmMain.frmAnalyse.m_vtkRenderForm.Show()
                myFrmMain.frmAnalyse.frmRectable.Activate()
                myFrmMain.frmAnalyse.frmRectable.TabText = "关心点超标率分析"
                myFrmMain.frmAnalyse.frmRectable.Text = "关心点超标率分析"

                '设置各点高值列表窗口上的下柆框
            End If
        End If


    End Sub

    Private Sub IntialResultControl(ByVal strText As String)
        My.Application.ApplicationContext.MainForm.Cursor = Cursors.WaitCursor

        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Dim myTreeNode As TreeNode
        '如果结点没有窗口则新建，否则激活
        If Me.TreeView1.SelectedNode IsNot Nothing Then
            myTreeNode = Me.TreeView1.SelectedNode

            If myTreeNode.Text = "各点高值" Then

                '设置控制窗口的类型为各点高值
                myFrmMain.frmAnalyse.frmResultControl.FileType = FileType.Rectable
                '设置控制窗口的下拉框
                myFrmMain.frmAnalyse.frmResultControl.cmbCon.SelectedIndex = 0
                If myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.SelectedIndex = 0
                End If
                If myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.SelectedIndex = 0
                End If
                If myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.SelectedIndex = 0
                End If
                If myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.SelectedIndex = 0
                End If

            ElseIf myTreeNode.Text = "所有点最大值" Then

                If myFrmMain.frmAnalyse.frmResultControl.cmbCon.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.SelectedIndex = 0
                End If
                If myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.SelectedIndex = 0
                End If

                If myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.SelectedIndex = 0
                End If
                If myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.SelectedIndex = 0
                End If

            ElseIf myTreeNode.Text = "逐步值" Then

                If myFrmMain.frmAnalyse.frmResultControl.cmbCon.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.SelectedIndex = 0
                End If


                If myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.SelectedIndex = 0
                End If


                If myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.SelectedIndex = 0
                End If




                If myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.SelectedIndex = 0
                End If


                If myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.SelectedIndex = 0
                End If

                '设置各点高值列表窗口上的下柆框





            ElseIf myTreeNode.Text = "超标率分析" Then


                If myFrmMain.frmAnalyse.frmResultControl.cmbCon.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbCon.SelectedIndex = 0
                End If



                If myFrmMain.frmAnalyse.frmResultControl.cmbGroups.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGroups.SelectedIndex = 0
                End If


                If myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbAverageTime.SelectedIndex = 0
                End If


                If myFrmMain.frmAnalyse.frmResultControl.cmbRectable.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbRectable.SelectedIndex = 0
                End If



                If myFrmMain.frmAnalyse.frmResultControl.cmbGrid.Items.Count > 0 Then
                    myFrmMain.frmAnalyse.frmResultControl.cmbGrid.SelectedIndex = 0
                End If
                '设置各点高值列表窗口上的下柆框
            End If
        End If


    End Sub
    Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
        Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(AermodProject0.SaveName).DirectoryName
        Dim strNameLast As String = CAermod.GetFileName(AermodProject0.SaveName)


        My.Application.ApplicationContext.MainForm.Cursor = Cursors.WaitCursor

        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Dim myTreeNode As TreeNode
        '如果结点没有窗口则新建，否则激活
        If Me.TreeView1.SelectedNode IsNot Nothing Then
            myTreeNode = Me.TreeView1.SelectedNode

            '关于三维窗口的创建与隐藏
            'myFrmMain.frmAnalyse.m_vtkRenderForm.Show(DockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document)
            If myTreeNode.Text = "各点高值" Or myTreeNode.Text = "所有点最大值" Or myTreeNode.Text = "逐步值" Or myTreeNode.Text = "超标率分析" Then
                '设置窗口的颜色
                InitialColor()
                myTreeNode.BackColor = Color.DodgerBlue
                myTreeNode.ForeColor = Color.White

                myFrmMain.frmAnalyse.frmGis_Map.FileType = FileType.Rectable
                Dim Index As Integer = myTreeNode.Parent.Index

                '设置当前项目为选中的项目
                Dim tempProj As CAermod.ProjSet = AermodProject0.ProjSetCollection.Item(Index).Clone
                If tempProj.ID <> myFrmMain.frmAnalyse.NowProj.ID Then
                    myFrmMain.frmAnalyse.NowProj = AermodProject0.ProjSetCollection.Item(Index).Clone

                    '下面的代码把方案保存到项目的文件夹中，并取名TempAermod.aer。在预测计算完成后，需要再反序列化该文件。这样做主要是为了减少主文件的大小和降低内存消耗。
                    Dim strTempName As String = PrjPath & "\" & strNameLast & "\" & "Aermod\" & AermodProject0.ProjSetCollection.Item(Index).ID & "\" & "TempAermod.aer" '获得保存结果方案文件的文件名
                    '打开方案的结果文件------------------------------
                    Dim fileStr As Stream
                    Dim formatter As IFormatter
                    Try
                        fileStr = File.Open(strTempName, FileMode.Open)

                        formatter = CType(New BinaryFormatter, IFormatter)
                        fileStr.Seek(0, SeekOrigin.Begin)
                        Dim obj As Object = formatter.Deserialize(fileStr)
                        ' All done
                        fileStr.Dispose()
                        fileStr.Close()
                        myFrmMain.frmAnalyse.NowProj.TempAermod = obj
                    Catch ex As Exception
                        fileStr.Dispose()
                        fileStr.Close()
                        MsgBox("在反序列化方案结果文件时出现意外错误!")
                        Exit Sub
                    End Try
                    ChangeProj()
                End If
                If myFrmMain.frmAnalyse.NowProj.TempAermod IsNot Nothing Then
                    SetResultControl(myTreeNode.Text) '设置控制窗口中的下柆框
                    IntialResultControl(myTreeNode.Text)
                    myFrmMain.frmAnalyse.frmGis_Map.m_manager.SetToExtent()
                End If
            End If


        End If
        My.Application.ApplicationContext.MainForm.Cursor = Cursors.Default
    End Sub
    Private Sub InitialColor()
        For Each newNode1 As TreeNode In TreeView1.Nodes
            For Each newNode2 As TreeNode In newNode1.Nodes
                For Each newNode3 As TreeNode In newNode2.Nodes
                    newNode3.BackColor = Color.White
                    newNode3.ForeColor = Color.Black
                Next
            Next
        Next
    End Sub
    ''' <summary>
    ''' 项目发生改变
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ChangeProj()


        Dim myFrmMain As frmMain = My.Application.ApplicationContext.MainForm
        Dim myproj As CAermod.ProjSet = myFrmMain.frmAnalyse.NowProj
        '地形数据的文件，包含了路径的。
        Dim DemFineNameTo3D As String = ""
        '有没有地形数据
        Dim IsHaveDem As Boolean = False
        If AermodProject0.Aermap.Control.DataFile.Length > 0 Then '如果有地形数据，得到地形数据的文件
            DemFineNameTo3D = AermodProject0.GetProjectPath & "\aermap\" & AermodProject0.DemFileFor3D
            IsHaveDem = True
        End If
        '在下面设置GIS图中的污染源、关心点、建筑物
        myFrmMain.frmAnalyse.frmGis_Map.m_manager.UnloadAllLayer()
        Dim Path As String = System.IO.Path.GetDirectoryName(AermodProject0.SaveName) & "\" & CAermod.GetFileName(AermodProject0.SaveName) & "\Aermod\" & myproj.ID
        myFrmMain.frmAnalyse.frmGis_Map.m_manager.ChangeProjPath(Path)
        myFrmMain.frmAnalyse.frmGis_Map.m_proj = myproj
        '如果图层已经保存则导入图层，否则新建图层并更污染源、关心点、建筑物等图
        If myproj.IsSavedResult = True Then
            If myFrmMain.frmAnalyse.frmGis_Map.m_manager.Load(Path, "GisProj") = False Then
                myFrmMain.frmAnalyse.frmGis_Map.CreateGis(True)
            End If
            myFrmMain.frmAnalyse.frmGis_Map.UpAllSource(AermodProject0.GetProjectPath & "\aermap\" & AermodProject0.TifFileForGid) '更新污染源、关心点、建筑物等图
            myFrmMain.frmAnalyse.frmGis_Map.m_manager.Save("GisProj") '统一用GisProj这个文件名来保存文件
        Else
            myFrmMain.frmAnalyse.frmGis_Map.CreateGis(True)
            '保存Gis图层
            myFrmMain.frmAnalyse.frmGis_Map.UpAllSource(AermodProject0.GetProjectPath & "\aermap\" & AermodProject0.TifFileForGid) '更新污染源、关心点、建筑物等图
            myFrmMain.frmAnalyse.frmGis_Map.m_manager.Save("GisProj") '统一用GisProj这个文件名来保存文件
            'myproj.IsSavedResult = True '把项目标记为保存
        End If
        '设置控制窗口中的项目为选中的项目
        myFrmMain.frmAnalyse.frmResultControl.proj = myproj



        '所有的接受点
        'Dim recept As CAermod.Receptor = myproj.TempAermod.Receptor
        'myproj.TempAermod.Source.AreaPolySources.AreaPolySource(0)
        'recept.SubGridCart(0)

        '左下角的UTM坐标
        'AermodProject0.GetLeftButtomUtmXY
        '如果没有地形数据时，提供的绘制区域，采用相对坐标
        Dim rect As New CAermod.RectArea
        rect.Xmin = AermodProject0.Aermod.Receptor.SubGridCart(0).Xinit
        rect.Xmax = AermodProject0.Aermod.Receptor.SubGridCart(0).Xinit + (AermodProject0.Aermod.Receptor.SubGridCart(0).Xnum - 1) * AermodProject0.Aermod.Receptor.SubGridCart(0).Ydelta
        rect.Ymin = AermodProject0.Aermod.Receptor.SubGridCart(0).Yinit
        rect.Ymax = AermodProject0.Aermod.Receptor.SubGridCart(0).Yinit + (AermodProject0.Aermod.Receptor.SubGridCart(0).Ynum - 1) * AermodProject0.Aermod.Receptor.SubGridCart(0).Ydelta
        'DemFineNameTo3D中保存了用于3D的DEM数据文件，可以正常使用了。




        ''3D相关的
        'Try
        '    '更新项目所在位置
        '    myFrmMain.frmAnalyse.m_vtkRenderForm.SetProjPath(Path)


        '    myFrmMain.frmAnalyse.m_vtkRenderForm.ChangeSource(IsHaveDem, DemFineNameTo3D, rect, myproj)


        'Catch ex As Exception

        'End Try




    End Sub
End Class